﻿using System;
using System.Collections;
using System.Runtime.CompilerServices;
using IESN.Enum;

namespace IESN.DM
{
    public class DmClass
    {
        #region DMMapping中的列

        private string dMObjectIndexName = string.Empty;
        public string DMObjectIndexName
        {
            get { return dMObjectIndexName; }
            set { dMObjectIndexName = value; }
        }

        private string dMAddressName = string.Empty;
        public string DMAddressName
        {
            get { return dMAddressName; }
            set { dMAddressName = value; }
        }

        private short condiIndex = 0;
        public short CondiIndex
        {
            get { return condiIndex; }
            set { condiIndex = value; }
        }

        private int dmAddress = -1;
        /// <summary>
        /// 内存地址
        /// </summary>
        public int DmAddress
        {
            get { return dmAddress; }
            set { dmAddress = value; }
        }

        private short dmCount = 0;
        /// <summary>
        /// DM长度
        /// </summary>
        public short DmCount
        {
            get { return dmCount; }
            set { dmCount = value; }
        }

        private DmNodeType dmNodeType = DmNodeType.Parent;
        /// <summary>
        /// 节点类型（父子）
        /// </summary>
        public DmNodeType DmNodeType
        {
            get { return dmNodeType; }
            set { dmNodeType = value; }
        }

        private string dmRelationID = string.Empty; 
        public string DmRelationID
        {
            get { return dmRelationID; }
            set { dmRelationID = value; }
        }

        private DmRWType dmRwType = DmRWType.Read;

        public DmRWType DmRwType
        {
            get { return dmRwType; }
            set { dmRwType = value; }
        }

        private string dMObjectComment = string.Empty;

        public string DMObjectComment
        {
            get { return dMObjectComment; }
            set { dMObjectComment = value; }
        }

        #endregion 

        #region 其他属性

        private string dataType = "W";
        public string DataType
        {
            get { return dataType; }
            set { dataType = value; }
        }

        private short dbBlockAddr = -1;
        public short DbBlockAddr
        {
            get { return dbBlockAddr; }
            set { dbBlockAddr = value; }
        }

      
        public byte[] dmContentByteArry;
        public byte[] DmContentByteArry
        {
            get { return dmContentByteArry; }
            set { dmContentByteArry = value; }
        }

        private string dmContent = string.Empty;
        /// <summary>
        /// DM内容
        /// </summary>
        public string DmContent
        {
            get { return dmContent; }
            set { dmContent = value; }
        }  

        /// <summary>
        /// 在PC内存中DM collection中的Index
        /// </summary>
        private short dmObjectId = -3;
        public short DmObjectId
        {
            get { return dmObjectId; }
            set { dmObjectId = value; }
        }

        private bool dmRunEventProcessThreadStatus = false;
        public bool DmRunEventProcessThreadStatus
        {
            get { return dmRunEventProcessThreadStatus; }
            set { dmRunEventProcessThreadStatus = value; }
        }

        private bool dmStatus = false;
        /// <summary>
        /// 为true的时候刷新内存，FALSE就不刷
        /// </summary>
        public bool DmStatus
        {
            get { return dmStatus; }
            set { dmStatus = value; }
        }

        private ArrayList dmWhichFormUsed = new ArrayList();
        public ArrayList DmWhichFormUsed
        {
            get { return dmWhichFormUsed; }
            set { dmWhichFormUsed = value; }
        }

        private bool isCondiObject = false;
        public bool IsCondiObject
        {
            get { return isCondiObject; }
            set { isCondiObject = value; }
        }

        private bool isDisplayed = false;
        /// <summary>
        /// 是否需要界面显示
        /// </summary>
        public bool IsDisplayed
        {
            get { return isDisplayed; }
            set { isDisplayed = value; }
        }

        private short objRunIndex = 0;
        /// <summary>
        /// 暂不清楚
        /// </summary>
        public short ObjRunIndex
        {
            get { return objRunIndex; }
            set { objRunIndex = value; }
        }

        private string[] w_elem_Content; 
        /// <summary>
        /// 写
        /// </summary>
        public string[] W_elem_Content
        {
            get { return w_elem_Content; }
            set { w_elem_Content = value; }
        }

        private short[] w_elem_Count; 
        public short[] W_elem_Count
        {
            get { return w_elem_Count; }
            set { w_elem_Count = value; }
        }

        private short[] w_elem_offset; 
        public short[] W_elem_offset
        {
            get { return w_elem_offset; }
            set { w_elem_offset = value; }
        }

        private bool[] w_elem_status; 
        public bool[] W_elem_status
        {
            get { return w_elem_status; }
            set { w_elem_status = value; }
        }

        private bool w_Elem_Used = false; 
        public bool W_Elem_Used
        {
            get { return w_Elem_Used; }
            set { w_Elem_Used = value; }
        }

        private short w_ElemCountS = -1; 
        public short W_ElemCountS
        {
            get { return w_ElemCountS; }
            set { w_ElemCountS = value; }
        }

        private DmRWType dmType = DmRWType.Read;
        /// <summary>
        /// DM类型
        /// </summary>
        public DmRWType DmType
        {
            get { return dmType; }
            set { dmType = value; }
        }

        public void AddFormNameToDmObjectWhereUsedList(string strformName)
        {
            this.dmWhichFormUsed.Add(strformName.ToUpper());
        }

        public void init_elem(short intElemCount)
        {
            short index = 0;
            if (intElemCount >= 1)
            {
                this.w_elem_offset = new short[intElemCount];
                this.w_elem_Count = new short[intElemCount];
                this.w_elem_Content = new string[intElemCount];
                this.w_elem_status = new bool[intElemCount];
                this.w_ElemCountS = intElemCount;

                short upperBound = (short)this.w_elem_status.GetUpperBound(0);
                for (index = 0; index <= upperBound; index++)
                {
                    this.w_elem_status[index] = false;
                }
                if (intElemCount >= 1)
                {
                    this.w_Elem_Used = true;
                }
            }
        }

        public DmCondiProcess DmObjectCondiProcessMethod;
        public DmEventProcess DmObjectEventProcessMethod;

        #endregion 

      
    } 

    public delegate void DmCondiProcess(DmClass obj1);
    public delegate void DmEventProcess(DmClass obj1);

    
}

